package com.lei.demo.service.imp;

import com.lei.demo.dao.TotalFormDAO;
import com.lei.demo.entity.TotalForm;
import com.lei.demo.service.TotalFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Shinelon on 2017/6/15.
 */
@Service("TotalFormService")
@Transactional(readOnly = true)
public class TotalFormServiceImpl implements TotalFormService {

    @Autowired
    TotalFormDAO totalFormDAO;

    @Override
    public void update(TotalForm totalForm) {
        totalFormDAO.update(totalForm);
    }

    @Override
    @Transactional(readOnly = false)
    public void save(TotalForm totalForm) {
        totalFormDAO.save(totalForm);
    }

    @Override
    @Transactional(readOnly = false)
    public void delete(int toid) {
        totalFormDAO.delete(toid);
    }

    @Override
    public List<TotalForm> findTotalForms(int toid) {
        return totalFormDAO.findTotalForm(toid);
    }

    @Override
    public List<TotalForm> findTotalForms(String username) {
        return totalFormDAO.findTotalForm(username);
    }

    @Override
    public List<TotalForm> getAllTotalForms() {
        return totalFormDAO.getAllTotalForms();
    }

    @Override
    public TotalForm findById(int toid) {
       List<TotalForm> totalForms = findTotalForms(toid);
       if (!totalForms.isEmpty()) {
           return totalForms.get(0);
       } else {
           return null;
       }
    }
}
